home *** CD-ROM | disk | FTP | other *** search
/ Oh!X 2001 Spring / Oh!X 2001 Spring Special CD-ROM (Japan).7z / Oh!X 2001 Spring Special CD-ROM (Japan) (Track 1).bin / GALAXY / ohx5-1 / render.cpp < prev    next >
C/C++ Source or Header  |  2001-01-10  |  3KB  |  116 lines

  1. /*
  2.     Oh!X5号
  3.     GalaxyKnightsサンプル1
  4.     レンダリング部分
  5. */
  6.  
  7. /*    ヘッダーインクルード    */
  8.  
  9. #include    "stdafx.h"
  10. #include    "ohx5_1.h"
  11.  
  12. int    camera_pos_disp;
  13.  
  14. /*-------------------------------------------
  15.     アプリケーションの動作を一時停止する
  16. --------------------------------------------*/
  17. void pause_draw()
  18. {
  19.     if (lpD3D) lpD3DD->Present(NULL,NULL,NULL,NULL);            // GDIサーフェイスを表示する
  20.     DrawMenuBar( hwndApp );                            // ウインドウのメニューバーを描画する
  21.     RedrawWindow(hwndApp, NULL, NULL, RDW_FRAME);    // ウインドウのフレームを描画する
  22. //    while (ShowCursor(TRUE)<0) {};                    // マウスカーソルを表示する
  23. }
  24.  
  25. /*-------------------------------------------
  26.     停止していたアプリケーションの動作を再開する
  27. --------------------------------------------*/
  28. void restart_draw()
  29. {
  30. //    while (ShowCursor(FALSE)>=0) {};                // マウスカーソルを消す
  31.  
  32.     
  33. }
  34.  
  35. /*
  36.     実処理
  37. */
  38. bool realtime_render(void)
  39. {
  40. HRESULT hr;
  41. float    scale;
  42. OBJ3D    *obp;
  43. DWORD    type,i,max;
  44. D3DXMATRIX matRotate,matTranslate,mat,matX,matY,matZ,matView,matScaling;
  45. D3DXVECTOR3    vec;
  46.     D3DXMatrixPerspectiveLH( &mat,1.0f,1.0f,1.0f,512.0f );
  47.  
  48. //    カメラマトリックスを求める
  49.     D3DXMatrixRotationX( &matX,camera_rud.x );
  50.     D3DXMatrixRotationY( &matY,camera_rud.y );
  51.     D3DXMatrixRotationZ( &matZ,camera_rud.z );
  52.     matView = matY * matX * matZ;
  53.     lpD3DD->SetTransform( D3DTS_PROJECTION, &mat);
  54. //    Zバッファ&バックバッファ・クリア
  55.     lpD3DD->Clear( 0 ,NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,255),1.0f,0 );
  56. //    描画の開始
  57.  
  58.     lpD3DD ->BeginScene();
  59.  
  60. //    lpD3DD->SetRenderState( D3DRS_CULLMODE,  D3DCULL_NONE );
  61. //    lpD3DD->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
  62. //    lpD3DD->SetRenderState( D3DRS_FILLMODE,  D3DFILL_SOLID );
  63.  
  64.     obp = objtop;
  65.     while( obp !=NULL ){
  66.         if( obp->type==0 ){ obp = obp->next; continue; }
  67.     //    スケーリング
  68.         scale = shapelist[obp->type].scale;
  69.         D3DXMatrixScaling( &matScaling,scale,scale,scale );
  70.     //    ローカル回転マトリックスを求める
  71.         D3DXMatrixRotationX( &matX,-obp->rudder.x );
  72.         D3DXMatrixRotationY( &matY,-obp->rudder.y );
  73.         D3DXMatrixRotationZ( &matZ,-obp->rudder.z );
  74.         matRotate = matZ * matX * matY * matScaling;
  75.  
  76.     //    中心座標をグローバル変換
  77.         vec = obp->pos - camera_pos;
  78.         D3DXVec3TransformNormal( &vec,&vec, &matView );
  79.  
  80.     // 移動
  81.         D3DXMatrixTranslation(&matTranslate,
  82.             vec.x,
  83.             vec.y,
  84.             vec.z );
  85.  
  86.  
  87.     // 変換行列を計算
  88.         mat = matRotate * matView * matTranslate;
  89.         lpD3DD->SetTransform( D3DTS_WORLD, &mat);
  90.         type = shapelist[obp->type].type;
  91.         if( type==FILE_DATA ){
  92.             max = shapelist[obp->type].mats;
  93.             for( i=0;i<max;i++ ){
  94.                 lpD3DD->SetMaterial( &shapelist[obp->type].lpmmats[i] );
  95.                 lpD3DD->SetTexture( 0,shapelist[obp->type].lpmtexs[i] );
  96.                 shapelist[obp->type].pt->DrawSubset( i );
  97.             }
  98.         } else {
  99.             shapelist[obp->type].pt->DrawSubset( 0 );    //    実際の描画
  100.         }
  101.         obp = obp->next;
  102.     }
  103.     lpD3DD->EndScene();
  104.  
  105.     // フレーム更新、フリップだろうがブリットだろうがこれでOK
  106.     hr = lpD3DD->Present(NULL,NULL,NULL,NULL);
  107. //    if (hr == DDERR_SURFACELOST || hr == DDERR_SURFACEBUSY)
  108.     {
  109.         // サーフェイスが失われている場合の処理
  110. //        return restore_surface();
  111.     }
  112.  
  113.     return SUCCEEDED(hr);
  114. }
  115.  
  116.